//
//  LoginViewController.m
//  Fragrance
//
//  Created by dllo on 15/5/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "LoginViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 80, 50)];
    label.text = @"用户名:";
    [self.view addSubview:label];
    label.layer.cornerRadius = 10;
    label.layer.masksToBounds = YES;
    userNameTF = [[UITextField alloc] initWithFrame:CGRectMake(120, 50, 200, 50)];
    userNameTF.backgroundColor = [UIColor clearColor];
    userNameTF.borderStyle = UITextBorderStyleRoundedRect;
    userNameTF.placeholder = @"请输入账号";
    userNameTF.delegate = self;
    [self.view addSubview:userNameTF];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 120, 80, 50)];
    label1.text = @"密码:";
    label1.layer.cornerRadius = 10;
    label1.layer.masksToBounds = YES;
    [self.view addSubview:label1];
    passWord = [[UITextField alloc] initWithFrame:CGRectMake(120, 120, 200, 50)];
    passWord.backgroundColor = [UIColor clearColor];
    passWord.borderStyle = UITextBorderStyleRoundedRect;
    passWord.placeholder = @"请输入密码";
    passWord.secureTextEntry = YES;
    passWord.delegate = self;
    [self.view addSubview:passWord];
    
    
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    loginButton.frame = CGRectMake(80, 200, 80, 40);
    loginButton.backgroundColor = [UIColor redColor];
    [loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    loginButton.layer.cornerRadius = 10;
    loginButton.layer.masksToBounds = YES;
    [self.view addSubview:loginButton];
    [loginButton addTarget:self action:@selector(touchLogin) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    registerButton.frame = CGRectMake(200, 200, 80, 40);
    registerButton.backgroundColor = [UIColor greenColor];
    [registerButton setTitle:@"注册" forState: UIControlStateNormal];
    registerButton.layer.cornerRadius = 10;
    registerButton.layer.masksToBounds = YES;
    [self.view addSubview:registerButton];
    [registerButton addTarget:self action:@selector(touchRegister) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [userNameTF resignFirstResponder];
    [passWord resignFirstResponder];
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [passWord resignFirstResponder];
    
    if (userNameTF.text.length == 0 || passWord.text.length == 0) {
        UIAlertView *alt = [[UIAlertView alloc] initWithTitle:@"友情提示" message:@"请输入完整信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alt.tag = 100;
        [alt show];
    }else
    {
                UIAlertView *alt2 = [[UIAlertView alloc] initWithTitle:@"友情提示" message:@"信息填写完成" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alt2 show];
}

    
    return YES;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"%ld", buttonIndex);
    if (alertView.tag == 100) {
        if (buttonIndex == 1) {
            if (userNameTF.text.length == 0) {
                [userNameTF becomeFirstResponder];
            }else
            {
                [passWord becomeFirstResponder];
            }
        }
    }
}

- (void)touchLogin
{

}
- (void)touchRegister
{
    RegisterViewController *registerView = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerView animated:YES];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
